package com.simpleaccount.Toast;

import android.content.Context;
import android.widget.Toast;

import es.dmoral.toasty.Toasty;

/**
 * Created by zhou on 2017/7/14.
 */

public class ToastUtils {
    static Toast currentToast=null;

    public static void toast(Context context, String text,String type){
        int iType=swithType(type);
        if(currentToast!=null){
            currentToast.cancel();
        }
        switch (iType){
            case 0:
               currentToast=Toasty.error(context,text,Toast.LENGTH_SHORT);
                currentToast.show();
                break;
            case 1:
                currentToast=Toasty.info(context,text,Toast.LENGTH_SHORT);
                currentToast.show();
                break;
            case 2:
                currentToast=Toasty.warning(context,text,Toast.LENGTH_SHORT);
                currentToast.show();
                break;
            case 3:
                currentToast=Toasty.success(context,text,Toast.LENGTH_SHORT);
                currentToast.show();
                break;
        }

    }

    public static void cancel(){
        if(currentToast!=null){
            currentToast.cancel();
            currentToast=null;
        }
    }
    public static int swithType(String type){
        int iType=1;
        if(type.equals("err")){
            iType=0;
        }else if(type.equals("info")){
            iType=1;
        }else if(type.equals("warning")){
            iType=2;
        }else if(type.equals("success")){
            iType=3;
        }
        return iType;
    }
}
